﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
//using HjKisTableAdapters;
using RGPWEB.App_Code.DAL;
using RGPWEB.App_Code.DAL.HjKisTableAdapters;

[System.ComponentModel.DataObject]

public class MCodeBll
{

    private a_McodeTableAdapter _productsAdapter = null;
    protected a_McodeTableAdapter Adapter
    {
        get
        {
            if (_productsAdapter == null)
                _productsAdapter = new a_McodeTableAdapter();

            return _productsAdapter;
        }
    }

    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public RGPWEB.App_Code.DAL.HjKis.a_McodeDataTable GetMCode()
     {
         return Adapter.GetMCode();
     }

    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public RGPWEB.App_Code.DAL.HjKis.a_McodeDataTable GetClassGroupName()
    {
        return Adapter.GetClassGroupName();
    }

    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public RGPWEB.App_Code.DAL.HjKis.a_McodeDataTable GetClassItem()
    {
        return Adapter.GetClassItem();
    }



    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public RGPWEB.App_Code.DAL.HjKis.a_McodeDataTable GetMCodeBy(int Pid)
    {
        return Adapter.GetMCodeBy(Pid);
    }


    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public RGPWEB.App_Code.DAL.HjKis.a_McodeDataTable GetDataByItem(string classItem)
    {
        return Adapter.GetDataByItem(classItem);
    }

    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public RGPWEB.App_Code.DAL.HjKis.a_McodeDataTable GetDataByClassGroupName(string classGroupName)
    {
        return Adapter.GetDataByClassGroupName(classGroupName);
    }

    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public RGPWEB.App_Code.DAL.HjKis.a_McodeDataTable GetDataByLike(string value)
    {
        return Adapter.GetDataByLike(value);
    }


    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public RGPWEB.App_Code.DAL.HjKis.a_McodeDataTable GetMcodeByList(string classItem, string classGroupName)
    {
        return Adapter.GetMcodeByList(classItem,classGroupName);
    }

    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public RGPWEB.App_Code.DAL.HjKis.a_McodeDataTable GetDataByItem_Group(string classItem, string classGroup)
    {
        if(classItem=="all")
            return Adapter.GetDataByGroup(classGroup);
        else
        return Adapter.GetDataByItem_Group(classItem, classGroup);
    }

   [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public RGPWEB.App_Code.DAL.HjKis.a_McodeDataTable GetDataByGroup(string classGroup)
    {
        return Adapter.GetDataByGroup(classGroup);
    }




    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]

    public bool UpdateQuery(string ClassItem, string ClassCode, string ClassType, string ClassNote, string ClassGroup, string ClassGroupName, int original_id)
    {

        RGPWEB.App_Code.DAL.HjKis.a_McodeDataTable Mcodes = Adapter.GetMCodeBy(original_id);
        if (Mcodes.Count == 0) return false;

        RGPWEB.App_Code.DAL.HjKis.a_McodeRow mcode = Mcodes[0];

      //  mcode.id = original_id;
        mcode.ClassItem = ClassItem;
        mcode.ClassCode = ClassCode;
        mcode.ClassType = ClassType;
        mcode.ClassNote = ClassNote;
        mcode.ClassGroup = ClassGroup;
        mcode.ClassGroupName = ClassGroupName;


        // Update the product record
        int rowsAffected = Adapter.Update(mcode);

        // Return true if precisely one row was updated, otherwise false
        return rowsAffected == 1;


    }


    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
    public bool InsertQuery(string ClassItem, string ClassCode, string ClassType, string ClassNote, string ClassGroup, string ClassGroupName)
    {
        // Create a new ProductRow instance
        RGPWEB.App_Code.DAL.HjKis.a_McodeDataTable mcodes = new RGPWEB.App_Code.DAL.HjKis.a_McodeDataTable();
        RGPWEB.App_Code.DAL.HjKis.a_McodeRow mcode = mcodes.Newa_McodeRow();

        mcode.ClassItem = ClassItem;
        mcode.ClassCode = ClassCode;
        mcode.ClassType = ClassType;
        mcode.ClassNote = ClassNote;
        mcode.ClassGroup = ClassGroup;
        mcode.ClassGroupName = ClassGroupName;

        // Add the new product
        mcodes.Adda_McodeRow(mcode);

        int rowsAffected = Adapter.Update(mcodes);

        // Return true if precisely one row was inserted, otherwise false
        return rowsAffected == 1;
    }


}
